﻿using System;
using System.IO;
using log4net;

namespace Helper.Log
{
    /// <summary>
    /// 日志工厂
    /// </summary>
    public static class LogFactory
    {

        /// <summary>
        /// 获取配置文件路径
        /// </summary>
        /// <param name="filePath">文件相对根目录的相对路径</param>
        /// <returns></returns>
        static string GetConfigPath(string filePath)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;//获取基目录，它由程序集冲突解决程序用来探测程序集。   
            // string str7 = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; 
            //获取或设置包含该应用程序的目录的名称。  
            return path + filePath;

        }
        static LogFactory()
        {

            //  FileInfo configFile = new FileInfo(HttpContext.Current.Server.MapPath("/Configs/log4net.config")); 
            FileInfo configFile = new FileInfo(GetConfigPath("log4net.config"));
            log4net.Config.XmlConfigurator.Configure(configFile);
        }
        /// <summary>
        /// 记录器
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static ILog GetLogger(Type type)
        {
            return new LogInfo(LogManager.GetLogger(type));
        }
        /// <summary>
        /// 记录器
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static ILog GetLogger(string str)
        {
            return new LogInfo(LogManager.GetLogger(str));
        }
    }

}
